import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread('CV-Pictures/gate.jpg')
h,w,c=img.shape
mask=np.zeros((h,w),np.uint8)
h1=np.int0(h/4)
h2=np.int0(h*0.75)
w1=np.int0(w/4)
w2=np.int0(w*0.75)
mask[h1:h2,w1:w2]=255
histb=cv2.calcHist([img],[0],mask,[256],[0,255])
histg=cv2.calcHist([img],[1],mask,[256],[0,255])
histr=cv2.calcHist([img],[2],mask,[256],[0,255])
cv2.imshow('img',img)
plt.plot(histb,color='b',label='blue-hist')
plt.plot(histg,color='g',label='green-label')
plt.plot(histr,'r',label='red-label')
plt.legend(loc='best')
plt.show()
cv2.imshow('mask',mask)
cv2.waitKey()
cv2.destroyAllWindows()